package com.oa.ylms.apps.dao.notice.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oa.ylms.apps.dao.notice.INoticeStaffDao;
import com.oa.ylms.apps.entity.notice.NoticeStaffValue;

@SuppressWarnings("unchecked")
public class NoticeStaffDaoImpl extends HibernateDaoSupport implements
		INoticeStaffDao {

	public int addNoticeStaff(NoticeStaffValue noticeStaff) throws Exception {
		if (noticeStaff != null) {
			this.getHibernateTemplate().save(noticeStaff);
			return noticeStaff.getId();
		}
		return 0;
	}

	public boolean deleteNoticeStaff(NoticeStaffValue noticeStaff)
			throws Exception {
		
		if (noticeStaff != null) {
			try {
				this.getHibernateTemplate().delete(noticeStaff);
			} catch (Exception e) {
				return false;
			}
			return true;
		}
		return false;
	}

	public List<NoticeStaffValue> queryNoticeStaffByNoticeId(int noticeId)
			throws Exception {
		return this.getHibernateTemplate().find(
				"select nsv from NoticeStaffValue nsv,StaffInfoValue siv,ArchiveInfoValue aiv where nsv.staffInfo.staffId = siv.staffId AND siv.archiveInfo.archiveId = aiv.archiveId AND nsv.noticeInfo.noticeId =? ", noticeId);
	}

}
